`
https://leetcode.cn/problems/4xy4Wx/
`

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var purchasePlans = function (nums, target) {
  // 同 LC 2824. 统计和小于目标的下标对数目
  nums.sort((a, b) => a - b)
  const n = nums.length
  const MOD = 1e9 + 7
  let res = 0
  let left = 0, right = n - 1

  while (left < right) {
    if (nums[left] + nums[right] <= target) {
      // nums[left + 1, right] 和 nums[left] 都是合法对
      res += (right - left) % MOD
      left++
    } else {
      right--
    }
  }

  return res % MOD
};